package com.xyzwps.orm.jpa.repository;

import com.xyzwps.orm.repository.TablesRepository;

import javax.persistence.EntityManager;
import java.util.Objects;

public class JpaTablesRepository implements TablesRepository {

    private final EntityManager em;

    public JpaTablesRepository(EntityManager em) {
        this.em = Objects.requireNonNull(em);
    }

    @Override
    public void cleanAllTables() {
        var tx = em.getTransaction();
        tx.begin();
        em.createQuery("delete from Tag").executeUpdate();
        em.createQuery("delete from User").executeUpdate();
        tx.commit();
    }

}
